﻿using BW.EatRabbit.API.Application.Commands.Farming;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.Farming
{
    public class FarmingCreateCommandHandler : IRequestHandler<FarmingCreateCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Farming_Company> _farmingRepository;
        public FarmingCreateCommandHandler(IBaseRepository<Farming_Company> farmingRepository)
        {
            _farmingRepository = farmingRepository;

        }
        public Task<APIResult<int>> Handle(FarmingCreateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            Farming_Company farming = new Farming_Company();
            farming.Breeding_Farm=request.Breeding_Farm;
            farming.Breeding_Person=request.Breeding_Person;
            farming.StocksNum=request.StocksNum;
            farming.ProductionBatch=request.ProductionBatch;
            farming.Creator = request.UserNickname;

            _farmingRepository.AddEntity(farming);

            return Task.FromResult(result);

        }
    }
}
